/*
 * Copyright (C) 2017 zhouyou(478319399@qq.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.shuyihui.rxhttp.api

import io.reactivex.Observable
import okhttp3.MultipartBody
import okhttp3.RequestBody
import okhttp3.ResponseBody
import retrofit2.http.*
import java.util.LinkedHashMap

interface ApiService {
    @POST
    @FormUrlEncoded
    fun post(@Url url: String, @FieldMap maps: LinkedHashMap<String?, String?>?): Observable<ResponseBody?>

    @POST
    fun postBody(@Url url: String, @Body `object`: Any): Observable<ResponseBody?>

    @POST
    @Headers("Content-Type: application/json", "Accept: application/json")
    fun postJson(@Url url: String, @Body jsonBody: RequestBody): Observable<ResponseBody?>

    @POST
    fun postBody(@Url url: String, @Body body: RequestBody): Observable<ResponseBody?>

    @GET
    operator fun get(
        @Url url: String,
        @QueryMap maps: LinkedHashMap<String?, String?>?
    ): Observable<ResponseBody?>

    @DELETE
    fun delete(
        @Url url: String,
        @QueryMap maps: LinkedHashMap<String?, String?>?
    ): Observable<ResponseBody?>

    //@DELETE()//delete body请求比较特殊 需要自定义
    @HTTP(method = "DELETE", hasBody = true)
    fun deleteBody(@Url url: String, @Body `object`: Any): Observable<ResponseBody?>

    //@DELETE()//delete body请求比较特殊 需要自定义
    @HTTP(method = "DELETE", hasBody = true)
    fun deleteBody(@Url url: String, @Body body: RequestBody): Observable<ResponseBody?>

    //@DELETE()//delete body请求比较特殊 需要自定义
    @Headers("Content-Type: application/json", "Accept: application/json")
    @HTTP(method = "DELETE", hasBody = true)
    fun deleteJson(@Url url: String, @Body jsonBody: RequestBody): Observable<ResponseBody?>

    @PUT
    fun put(@Url url: String, @QueryMap maps: LinkedHashMap<String?, String?>?): Observable<ResponseBody?>

    @PUT
    fun putBody(@Url url: String, @Body `object`: Any): Observable<ResponseBody?>

    @PUT
    fun putBody(@Url url: String, @Body body: RequestBody): Observable<ResponseBody?>

    @PUT
    @Headers("Content-Type: application/json", "Accept: application/json")
    fun putJson(@Url url: String, @Body jsonBody: RequestBody): Observable<ResponseBody?>

    @Multipart
    @POST
    fun uploadFlie(
        @Url fileUrl: String,
        @Part("description") description: RequestBody,
        @Part("files") file: MultipartBody.Part
    ): Observable<ResponseBody?>

    @Multipart
    @POST
    fun uploadFiles(
        @Url url: String,
        @PartMap maps: Map<String, RequestBody>
    ): Observable<ResponseBody?>

    @Multipart
    @POST
    fun uploadFiles(@Url url: String, @Part parts: List<MultipartBody.Part>): Observable<ResponseBody?>

    @Streaming
    @GET
    fun downloadFile(@Url fileUrl: String): Observable<ResponseBody?>
}
